package com.interesting.client.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.interesting.R;
import com.interesting.client.bean.Music;

public class MusicListAdapter extends BaseAdapter {

	private Context context;
	private List<Music> dataList;
	private LayoutInflater inflater;

	public MusicListAdapter(Context context, List<Music> dataList) {
		this.context = context;
		this.dataList = dataList;
		this.inflater = LayoutInflater.from(context);
	}

	public class ViewHolder {
		public TextView title, person;

	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int positon, View convertView, ViewGroup parent) {
		final Music music = dataList.get(positon);
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.music_item_adapter, null);
			ViewHolder vh = new ViewHolder();
			vh.title = (TextView) convertView.findViewById(R.id.music_item_adapter_title);
			vh.person = (TextView) convertView.findViewById(R.id.music_item_adapter_person);
			convertView.setTag(vh);
		}
		ViewHolder holder = (ViewHolder) convertView.getTag();
		holder.title.setText(music.getVtitle());
		holder.person.setText(music.getVperson());
		return convertView;
	}
}
